package com.sishu.websocket4.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sishu.websocket4.pojo.Assets;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AssetsMapper extends BaseMapper<Assets> {

//    @Insert("INSERT INTO `Groups` (group_member,group_id) VALUES (#{groupMember},#{gruopId})")
//    void insertAssets(Assets assets);

    @Select("select * from Assets where user_id = #{userId} and group_id = #{groupId}")
    Assets selectbyUserId(String userId,String groupId);


    @Update("UPDATE Assets SET fluid_assets =#{asset},fixed_assets =fixed_assets + #{fixed_assets} where user_id = #{userId}")
    void updateassets(String userId,int asset,int fixed_assets);

    //总资产++,流动资金++,适用于交易,答题扣款
    @Update("UPDATE Assets SET total_assets = total_assets-#{amount},fluid_assets =fluid_assets - #{amount} where user_id = #{userId} and group_id = #{groupid}")
    void updateassetjian(String userId, int amount,String groupid);

    //总资产++,流动资金++,适用于交易,答题扣款
    @Update("UPDATE Assets SET total_assets = total_assets + #{amount},fluid_assets =fluid_assets + #{amount} where user_id = #{userId} and group_id = #{groupid}")
    void updateassetjia(String userId, int amount,String groupid);


    //总资产不变,流动资金++,固定资金--,适用于卖地
    @Update("UPDATE Assets SET fluid_assets = fluid_assets - #{amount},fixed_assets =fixed_assets - #{amount} where user_id = #{userId} and group_id = #{groupid}")
   void  updateassetjianfixed(String userId, int amount,String groupid);

    @Select("select a.*,U.user_name from Assets a join Users U ON  a.user_id = U.user_id where group_id = #{groupid}")
    List<Assets> selectbygroupid(String groupid);
}
